<template>
  <div class="_playVideo">
    <van-nav-bar :title="videoInfo.name" left-text="返回首页" left-arrow @click-left="onClickLeft" />
    <video
      class="video"
      v-if="videoInfo.url"
      style="width:100%; object-fit: fill"
      playsinline
      controls
      x5-video-player-type="h5"
      :src="videoInfo.url"
    ></video>
  </div>
</template>

<script>
import { videoList } from "@/config/videoList";
import qs from "qs";
import { NavBar } from "vant";
import {
  shareConfig,
  shareConfig2,
  createShareUrl,
  shareRouter,
  shareImg,
} from "@/config/shareConfig";
import wxJSFn from "@/js/wxJSFn";
export default {
  components: {
    [NavBar.name]: NavBar,
  },
  data() {
    return {
      videoInfo: {
        url: "",
        name: "",
      },
      urlShareId: 0,
      urlParam: {},
    };
  },
  created() {
    let url1 = window.location.href.split("#")[0];
    let param = qs.parse(url1.split("?")[1]);
    this.urlShareId = param.shareId;
    console.log(param);
    this.urlParam = param;
    let vid = param.vid;
    this.videoInfo = videoList[vid];
  },
  computed: {
    shareParams() {
      return this.$store.state.shareParams;
    },
  },
  watch: {
    shareParams: {
      deep: true,
      immediate: true,
      handler(val) {
        if (val && val.shareId) {
          this.$nextTick(() => {
            if (val.shareId != this.urlShareId) {
              let param = JSON.parse(JSON.stringify(this.urlParam));
              param.shareId = val.shareId;
              let url = qs.stringify(param);
              let link = `http://app.aptenon.com/crm/dist/activity.html?${url}#/activityPage7/playVideo`;
              console.log(link);
              window.location.href = link;
            } else {
              let obj = {
                aid: this.$store.state.aid,
                shareId: val.shareId,
                vid: this.urlParam.vid,
              };
              let link = "";
              let sConfig = shareConfig2;
              link = createShareUrl(
                obj,
                this.$route.path,
                shareRouter.videoRouter
              );
              console.log("shareLinkVideo", link);
              wxJSFn.share({
                ...sConfig,
                desc: this.videoInfo.name,
                link,
                imgUrl: shareImg,
              });
            }
          });
        }
      },
    },
  },
  methods: {
    onClickLeft() {
      this.$router.push({
        name: "act7index",
      });
    },
  },
};
</script>

<style lang="scss">
._playVideo {
  width: 100%;
  box-sizing: border-box;
  .van-nav-bar__left {
    padding: 0 4px;
  }
  .van-nav-bar__title {
    max-width: 50%;
  }
}
</style>